package com.yc.biz.impl;

import java.util.List;
import java.util.Map;

import com.yc.bean.PayType;
import com.yc.biz.PayTypeBiz;
import com.yc.dao.DBHelper;

public class PayTypeBizImpl implements PayTypeBiz {
	DBHelper db=new DBHelper();
	@Override
	public List<PayType> findAll(int uid) {
		String sql="select ptype,money from paytype,payuseinfo where paytype.ptid=payuseinfo.ptid and uid="+uid;
		return db.find(sql, null, PayType.class);
	}
	@Override//更新金额
	public int updateMoney(int uid,double price,String paytype) {
		String sql1="select paytype.ptid,money from paytype,payuseinfo where paytype.ptid=payuseinfo.ptid and  ptype='"+paytype+"' and uid="+uid;
		List<Map<String,String>> list=db.findAll(sql1, null);
		int ptid=Integer.parseInt(list.get(0).get("ptid"));
		double money=Double.parseDouble(list.get(0).get("money"));
		money+=price;
		String sql="update payuseinfo set money="+money+" where ptid="+ptid+" and uid="+uid;
		return db.doUpdate(sql, null);
	}

}
